package com.ljb.demompandroidchart;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.ljb.demompandroidchart.mpchartutils.LineUtils;
import com.ljb.demompandroidchart.mpchartutils.OnValueTouchListener;
import com.ljb.demompandroidchart.mpchartutils.PieUtils;


public class MainActivity extends AppCompatActivity {

    float[] mData = {10.01f, 40.43f, 50.789347f};
    String[] mParties1 = {"嘎嘎", "嘻嘻", "呵呵"};
    String[] mParties2 = {"嘎嘎", "嘻嘻",};
    String[] xData = {"周一", "周二", "周三"};
    String[] mColors = {"#56A0F4FF", "#56FE9A69", "#56FD9E51", "#56936CAF"};
    float[][] lineData = {{20.89f, 80.3453f, 50.89f}, {40.3453f, 20.84848f, 70.098f}};

    private PieChart piechart;
    private LineChart linechart;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        piechart = (PieChart) findViewById(R.id.piechart);
        linechart = (LineChart) findViewById(R.id.linechart);

        showPie();
        showLine();
    }

    private void showLine() {
      LineUtils.getInstance(this)
                .initChart(linechart)
                .setLegend(true)//显示图例
                .highlightEnable(true)
                .setXData(xData)
                .setYData(lineData, mParties2)
                .setOnValueTouchListener(new OnValueTouchListener() {
                    @Override
                    public void onValueSelected(Entry e, Highlight h) {

                    }
                }).show();
    }

    private void showPie() {
        PieUtils.getInstance(this)
                .initChart(piechart)
                .setLegend(false)//是否显示图例
                .setData(mData, mParties1, null)//设置数据
                .setOnValueTouchListener(new OnValueTouchListener() {
                    @Override
                    public void onValueSelected(Entry e, Highlight h) {

                    }
                }).show();
    }
}
